// Copyright (c) 2022 toimc<admin@wayearn.com>
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import "module-alias/register";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { setupApp } from "./setup";
import { getServerConfig } from "../ormconfig";
import Chalk from "chalk";
import { Logger } from "@/common/log4js/log4j.util";
import { getLocalIP } from "@/common/utils/common";

async function bootstrap() {
    const config = getServerConfig();
    const app = await NestFactory.create(AppModule, {
        // 关闭整个nestjs日志
        // logger: flag && [],
        // logger: false,
        // 允许跨域
        cors: true
        // logger: ['error', 'warn'],
    });
    setupApp(app);
    const port =
        typeof config["APP_PORT"] === "string"
            ? parseInt(config["APP_PORT"])
            : 3000;
    // await app.init(); //放在listen之后定时任务报错
    await app.listen(port);
    const localIp = getLocalIP();
    Logger.log(
        `--------------------------------------------------`,
        "\n",
        Chalk.magenta(`服务启动成功 `),
        `http://localhost:${config.APP_PORT}${config.API_PREFIX}`,
        "\n",
        `             `,
        `http://${localIp}:${config.APP_PORT}${config.API_PREFIX}`,
        "\n",
        "\n",
        Chalk.green(`swagger文档地址`),
        `http://localhost:${config.APP_PORT}/doc.html`,
        "\n",
        `               `,
        `http://${localIp}:${config.APP_PORT}/doc.html`,
        "\n",
        `--------------------------------------------------`
    );
}


bootstrap();

// import setupCluster from "./setup-cluster";
// setupCluster(bootstrap)






